package com.ctrip.demo.java8;

import java.util.LinkedHashSet;
import java.util.Set;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author xs.wu
 */
public class LockTest {

    public static void main(String[] args) {
        ReentrantLock reentrantLock = new ReentrantLock();
        reentrantLock.lock();
        try {
            for (int i = 0; i < 10; i++) {
                System.out.println("xxx" + i);
                if (i == 3) {
                    break;
                }
            }
        } finally {
            reentrantLock.unlock();
            System.out.println("release lock");
        }

        int res;
        Set<Integer> set = new LinkedHashSet<>();
        res = set.stream().filter(s -> s != 1).mapToInt(s -> s).sum();
    }

//    @Configuration
//    @ConditionalOnClass(RedisOperations.class)
//    @EnableConfigurationProperties(RedisProperties.class)
//    @EnableCaching
//    public class RedisConfig extends CachingConfigurerSupport {
//
//        @Bean
//        public RedisTemplate<String, Object>  redisTemplate(RedisConnectionFactory redisConnectionFactory) {
//            RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
//            redisTemplate.setConnectionFactory(redisConnectionFactory);
//            Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
//
//            ObjectMapper objectMapper = new ObjectMapper();
//            objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
//            objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
//
//            jackson2JsonRedisSerializer.setObjectMapper(objectMapper);
//
//            //重点在这四行代码
//            redisTemplate.setKeySerializer(new StringRedisSerializer());
//            redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
//            redisTemplate.setHashKeySerializer(new StringRedisSerializer());
//            redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);
//
//            redisTemplate.afterPropertiesSet();
//            return redisTemplate;
//        }
//
//    }
}
